import { defineStore } from 'pinia';
import { ref, computed } from 'vue';

export const useAppStore = defineStore('app', () => {
  // 状态
  const loading = ref(false);
  const theme = ref('light');
  const language = ref('zh-CN');

  // 计算属性
  const isLoading = computed(() => loading.value);
  const isDark = computed(() => theme.value === 'dark');

  // 方法
  const setLoading = isLoading => {
    loading.value = isLoading;
  };

  const toggleTheme = () => {
    theme.value = theme.value === 'light' ? 'dark' : 'light';
  };

  const setLanguage = lang => {
    language.value = lang;
  };

  return {
    // 状态
    loading,
    theme,
    language,
    // 计算属性
    isLoading,
    isDark,
    // 方法
    setLoading,
    toggleTheme,
    setLanguage
  };
});
